package org.example.ch16;

import org.slf4j.LoggerFactory;

import java.util.logging.Logger;

/**
 * https://leetcode-cn.com/problems/number-of-1-bits/
 *
 */
public class HammingWeight {


    // you need to treat n as an unsigned value
    public int hammingWeight(int n) {
        int ret = 0;
        for (int i = 0; i < 32; i++) {
            if((n & (1 << i))!=0){
                ret++;
            }
        }
        return ret;
    }

    public static void main(String[] args) {
        HammingWeight h = new HammingWeight();
        int result=h.hammingWeight(00000000000000000000000000001011);
        System.out.println(result);
    }
}
